﻿using AbpApplication.InPut;
using HandyControl.Controls;
using NewWms.Apiservice;
using Prism.Commands;
using Prism.Mvvm;
using Prism.Services.Dialogs;
using Reconstruct_Desktop.Apiservice.Dto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace NewWms.ViewModels.DialogsModel
{
    public class CreateBoxsDialogModel : BindableBase, IDialogAware
    {

        public DelegateCommand<string> Command { get; set; }
        private readonly IBaseService baseService;
        private InPut_BaseService inPut_BaseServie;
        public InPut_BaseService InPut_BaseServie
        {
            get { return inPut_BaseServie; }
            set { inPut_BaseServie = value;RaisePropertyChanged(); }
        }
        private List<BoxTypeDto> boxTypeDtos;
        public List<BoxTypeDto> BoxTypeDtos
        {
            get { return boxTypeDtos; }
            set { boxTypeDtos = value; RaisePropertyChanged(); }
        }



        public CreateBoxsDialogModel() 
        { 
           Command=new DelegateCommand<string>(Method);
           baseService = new BaseService();
           InPut_BaseServie=new InPut_BaseService();
           BoxTypeDtos = new List<BoxTypeDto>();
           Getlist_Bintypes();
        }

        public async void Method(string obj)
        {
            switch (obj)
            {
                case "CloseDialog": RequestClose?.Invoke(null);break;
                case "Create_Boxs": Create_Boxs();   break;
            }
        }

        //添加箱盒
        private async void Create_Boxs()
        {
        
            bool Nullres = InPut_BaseServie.GetType().GetProperties().All(property => property.GetValue(InPut_BaseServie) != null);
            if (!Nullres) { MessageBox.Warning("请填写完整"); return; }
            bool res= await baseService.Create_Boxs(InPut_BaseServie);
            if(res) RequestClose?.Invoke(null);
        }

        private async void Getlist_Bintypes()
        {
            BoxTypeDtos = await baseService.Getlist_Bintypes();
        }










        public string Title { get; set; }="新建存储料盒";
        public event Action<IDialogResult> RequestClose;
        public bool CanCloseDialog()
        {
            return true;
        }
        public void OnDialogClosed()
        {
            
        }
        public void OnDialogOpened(IDialogParameters parameters)
        {
          
        }
    }
}
